home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
cdialog.c
< prev
next >
Wrap
Text File
|
1992-04-17
|
11KB
|
417 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#if !defined(USEDUMP)
#include "maclib.h"
#include "termdef.h"
#include "tn3270funcs.h"
#include "globals.h"
#else
#pragma load "tn3270DumpFile"
#endif
#pragma segment 3270seg2
#define PICKERWIDTH 430
#define PICKERHEIGHT 282
extern PaletteHandle myPalette;
extern RGBColor realblack, realwhite;
cnr *cdlgcp;
PaletteHandle dlgpalette;
void colordlg(cnr *cp)
{
DialogPtr dlgptr;
DialogPeek dStorage;
WindowPtr behind;
pascal Boolean (*filterProc) ();
short gtype;
Handle gitem, itmlist;
Rect gbox, mybox, dlgbox;
short i;
GrafPtr gp;
short itemHit;
short * itemHitPtr;
RGBColor actual;
char tbase, texact, tinvert;
RGBColor twhite, tyellow, tpink, tturquoise, tgreen,
tred, tblue, tblack, tback, tstat;
static RGBColor dwhite = DFLTWHITE;
static RGBColor dyellow = DFLTYELLOW;
static RGBColor dpink = DFLTPINK;
static RGBColor dturquoise = DFLTTURQUOISE;
static RGBColor dgreen = DFLTGREEN;
static RGBColor dred = DFLTRED;
static RGBColor dblue = DFLTBLUE;
static RGBColor dblack = DFLTBLACK;
static RGBColor dback = DFLTBACK;
static RGBColor dstat = DFLTSTAT;
static RGBColor ctdpink = CTDFLTPINK;
static RGBColor ctdturquoise = CTDFLTTURQUOISE;
static RGBColor ctdblue = CTDFLTBLUE;
static RGBColor ctdback = CTDFLTBACK;
RGBColor rgbtemp;
GDHandle currGD;
short scrhsize, scrvsize;
short whsize, wvsize;
Rect r;
dStorage = 0;
behind = (WindowPtr)-1;
dlgbox.top = 16;
dlgbox.left = 44;
dlgbox.bottom = 326;
dlgbox.right = 469;
itmlist = GetResource('DITL', 268);
if (itmlist == 0) return;
HandToHand(&itmlist);
if (itmlist == 0) return;
dlgptr = NewCDialog(dStorage, &dlgbox, "\pColors", 0, 3, behind,
0, 0L, itmlist);
/* center the dialog on the current gDevice */
if (cp->myWindow != 0) {
GetGlobalRect(cp->myWindow, &r);
currGD = myGetMaxDevice(&r);
}
else {
currGD = GetMainDevice();
}
gbox = (*currGD)->gdRect;
scrhsize = gbox.right - gbox.left;
scrvsize = gbox.bottom - gbox.top;
whsize = dlgptr->portRect.right-dlgptr->portRect.left;
wvsize = dlgptr->portRect.bottom - dlgptr->portRect.top;
MoveWindow(dlgptr, gbox.left + (scrhsize-whsize)/2,
gbox.top + (scrvsize-wvsize)/3, 0);
dlgpalette = NewPalette(11, 0L, pmCourteous, 0);
SetPalette(dlgptr, dlgpalette, true);
fixcolors(dlgpalette, cp);
ActivatePalette(dlgptr);
/* define routine to draw user item */
cdlgcp = cp;
for (i=5; i < 24; i+=2) {
GetDItem(dlgptr, i, >ype, &gitem, &mybox);
SetDItem(dlgptr, i, gtype, (Handle)colorbox, &mybox);
}
/* define check boxes */
defcbox(dlgptr, cp);
arrowcursor();
ShowWindow(dlgptr);
/* frame the default selection */
GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
GetPort(&gp);
SetPort(dlgptr);
PenSize(3,3);
InsetRect(&gbox, -4, -4);
FrameRoundRect(&gbox, 16, 16);
PenSize(1,1);
SetPort(gp);
itemHit = 99;
itemHitPtr = &itemHit;
filterProc = DlgFilter;
/* copy current settings */
tbase = cp->cs.basecolor;
texact = cp->cs.exactcolor;
tinvert = cp->cs.invertbw;
twhite = cp->cs.usrwhite;
tyellow = cp->cs.usryellow;
tpink = cp->cs.usrpink;
tturquoise = cp->cs.usrturquoise;
tgreen = cp->cs.usrgreen;
tred = cp->cs.usrred;
tblue = cp->cs.usrblue;
tblack = cp->cs.usrblack;
tback = cp->cs.usrback;
tstat = cp->cs.usrstat;
while ((itemHit != 1) && (itemHit != 3)) {
ModalDialog((ModalFilterProcPtr)filterProc, itemHitPtr);
switch(itemHit) {
case 1: /* OK */
if (cp->myWindow != 0) fixcolors(cp->myPalette, cp);
break;
case 2: /* Set Default */
cp->cs.usrwhite = dwhite;
cp->cs.usryellow = dyellow;
cp->cs.usrgreen = dgreen;
cp->cs.usrred = dred;
cp->cs.usrblack = dblack;
cp->cs.usrstat = dstat;
if (cp->cs.exactcolor) {
cp->cs.usrpink = dpink;
cp->cs.usrturquoise = dturquoise;
cp->cs.usrblue = dblue;
cp->cs.usrback = dback;
}
else {
cp->cs.usrpink = ctdpink;
cp->cs.usrturquoise = ctdturquoise;
cp->cs.usrblue = ctdblue;
cp->cs.usrback = ctdback;
}
if (!(cp->cs.exactcolor)) {
cp->cs.exactcolor = 1;
fixcolors(dlgpalette, cp);
ActivatePalette(dlgptr);
cp->cs.exactcolor = 0;
}
cp->cs.basecolor = 0;
cp->cs.invertbw = 0;
defcbox(dlgptr, cp);
fixcolors(dlgpalette, cp);
ActivatePalette(dlgptr);
if (cp->myWindow != 0) {
GetEntryColor(dlgpalette, RGBback, &rgbtemp);
GetPort(&gp);
SetPort(cp->WritePtr);
if (cp->textmap) setgdev(cp);
RGBBackColor(&rgbtemp);
if (cp->PictPtr != 0) {
SetPort(cp->PictPtr);
RGBBackColor(&rgbtemp);
}
if (cp->textmap) resetgdev();
SetPort(gp);
}
updcolors(dlgptr);
break;
case 3: /* Cancel */
cp->cs.basecolor = tbase;
cp->cs.exactcolor = texact;
cp->cs.invertbw = tinvert;
cp->cs.usrwhite = twhite;
cp->cs.usryellow = tyellow;
cp->cs.usrpink = tpink;
cp->cs.usrturquoise = tturquoise;
cp->cs.usrgreen = tgreen;
cp->cs.usrred = tred;
cp->cs.usrblue = tblue;
cp->cs.usrblack = tblack;
cp->cs.usrback = tback;
cp->cs.usrstat = tstat;
fixcolors(dlgpalette, cp);
ActivatePalette(dlgptr);
if (cp->myWindow != 0) {
GetEntryColor(dlgpalette, RGBback, &rgbtemp);
GetPort(&gp);
SetPort(cp->WritePtr);
if (cp->textmap) setgdev(cp);
RGBBackColor(&rgbtemp);
if (cp->PictPtr != 0) {
SetPort(cp->PictPtr);
RGBBackColor(&rgbtemp);
}
if (cp->textmap) resetgdev();
SetPort(gp);
}
break;
case 5: /* white */
case 6:
getclr(dlgptr, "white", &(cp->cs.usrwhite), cp);
break;
case 7: /* yellow */
case 8:
getclr(dlgptr, "yellow", &(cp->cs.usryellow), cp);
break;
case 9: /* turquoise */
case 10:
getclr(dlgptr, "turquoise", &(cp->cs.usrturquoise), cp);
break;
case 11: /* green */
case 12:
getclr(dlgptr, "green", &(cp->cs.usrgreen), cp);
break;
case 13: /* pink */
case 14:
getclr(dlgptr, "pink", &(cp->cs.usrpink), cp);
break;
case 15: /* red */
case 16:
getclr(dlgptr, "red", &(cp->cs.usrred), cp);
break;
case 17: /* blue */
case 18:
getclr(dlgptr, "blue", &(cp->cs.usrblue), cp);
break;
case 19: /* black */
case 20:
getclr(dlgptr, "black", &(cp->cs.usrblack), cp);
break;
case 21: /* background */
case 22:
getclr(dlgptr, "bkground", &(cp->cs.usrback), cp);
GetEntryColor(dlgpalette, RGBback, &rgbtemp);
GetPort(&gp);
if (cp->myWindow != 0) {
SetPort(cp->WritePtr);
if (cp->textmap) setgdev(cp);
RGBBackColor(&rgbtemp);
if (cp->textmap) resetgdev();
}
actualcolor(&rgbtemp, &actual, cp);
if (actual == realwhite) {
cp->cs.invertbw = 1;
defcbox(dlgptr, cp);
}
else if (actual == realblack) {
cp->cs.invertbw = 0;
defcbox(dlgptr, cp);
}
if (cp->PictPtr != 0) {
if (cp->textmap) setgdev(cp);
SetPort(cp->PictPtr);
RGBBackColor(&rgbtemp);
if (cp->textmap) resetgdev();
}
SetPort(gp);
break;
case 23: /* status line */
case 24:
getclr(dlgptr, "status", &(cp->cs.usrstat), cp);
break;
case 25: /* base color */
cp->cs.basecolor ^= 1;
defcbox(dlgptr, cp);
break;
case 26: /* exact color */
cp->cs.exactcolor ^= 1;
fixcolors(dlgpalette, cp);
ActivatePalette(dlgptr);
updcolors(dlgptr);
defcbox(dlgptr, cp);
break;
case 27: /* invert black and white */
cp->cs.invertbw ^= 1;
defcbox(dlgptr, cp);
break;
default:
break;
}
}
DisposDialog(dlgptr);
}
void getclr(DialogPtr dlgptr, unsigned char *cname, RGBColor *cin, cnr *cp)
{
GrafPtr gp;
Point where;
short result;
short gtype;
Handle gitem;
Rect gbox, r;
unsigned char prompt[48];
RGBColor cout;
GDHandle currGD;
short scrhsize, scrvsize;
strcpy(prompt, "Select color for ");
strcat(prompt, cname);
strcat(prompt, ":");
GetPort(&gp);
if (cp->myWindow != 0) {
SetPort(cp->myWindow);
}
/* center color picker on current gDevice */
if (cp->myWindow != 0) {
GetGlobalRect(cp->myWindow, &r);
currGD = myGetMaxDevice(&r);
}
else {
currGD = GetMainDevice();
}
gbox = (*currGD)->gdRect;
scrhsize = gbox.right - gbox.left;
scrvsize = gbox.bottom - gbox.top;
where.h = gbox.left + (scrhsize-PICKERWIDTH)/2;
where.v = gbox.top + (scrvsize-PICKERHEIGHT)/3;
c2pstr(prompt);
result = GetColor(where, prompt, cin, &cout);
p2cstr(prompt);
if (result) {
*cin = cout;
fixcolors(dlgpalette, cp);
ActivatePalette(dlgptr);
updcolors(dlgptr);
}
/* frame the default selection again */
GetDItem(dlgptr, 1, >ype, &gitem, &gbox);
SetPort(dlgptr);
PenSize(3,3);
InsetRect(&gbox, -4, -4);
FrameRoundRect(&gbox, 16, 16);
PenSize(1,1);
SetPort(gp);
}
void defcbox(DialogPtr dlgptr, cnr *cp)
{
short gtype;
Handle gitem;
Rect gbox;
GetDItem(dlgptr, 25, >ype, &gitem, &gbox);
SetCtlValue((ControlHandle)gitem, cp->cs.basecolor);
GetDItem(dlgptr, 26, >ype, &gitem, &gbox);
SetCtlValue((ControlHandle)gitem, cp->cs.exactcolor);
GetDItem(dlgptr, 27, >ype, &gitem, &gbox);
SetCtlValue((ControlHandle)gitem, cp->cs.invertbw);
}
void updcolors(DialogPtr dlgptr)
DialogPtr dlgptr;
{
Rect crect;
GrafPtr gp;
crect.top = 5;
crect.left = 5;
crect.bottom = 295;
crect.right = 100;
GetPort(&gp);
SetPort(dlgptr);
InvalRect(&crect);
SetPort(gp);
}